﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using BangleCMS.DBUtility;
using SystemModel;

namespace BangleCMS.DAL
{
    /// <summary>
    /// 数据访问类:sys_user
    /// </summary>
    public partial class sys_userDAL
    {
        /// <summary>
		/// 得到一个对象实体
		/// </summary>
        public BangleCMS.Model.sys_user UserLogin(string Account, string Password)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select UserId,UserName,LoginName,LoginPwd,RoleId,CreateUser,CreateDate,UpdateUser,UpdateDate,Valid from sys_user ");
            strSql.Append(" where Valid=1 AND LoginName=@LoginName AND LoginPwd=@LoginPwd");
            MySqlParameter[] parameters = {
					new MySqlParameter("@LoginName", MySqlDbType.VarChar),
                    new MySqlParameter("@LoginPwd", MySqlDbType.VarChar)
			};
            parameters[0].Value = Account;
            parameters[1].Value = Password;

            BangleCMS.Model.sys_user model = new BangleCMS.Model.sys_user();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "")
                {
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoginName"] != null && ds.Tables[0].Rows[0]["LoginName"].ToString() != "")
                {
                    model.LoginName = ds.Tables[0].Rows[0]["LoginName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoginPwd"] != null && ds.Tables[0].Rows[0]["LoginPwd"].ToString() != "")
                {
                    model.LoginPwd = ds.Tables[0].Rows[0]["LoginPwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["RoleId"] != null && ds.Tables[0].Rows[0]["RoleId"].ToString() != "")
                {
                    model.RoleId = int.Parse(ds.Tables[0].Rows[0]["RoleId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateUser"] != null && ds.Tables[0].Rows[0]["CreateUser"].ToString() != "")
                {
                    model.CreateUser = int.Parse(ds.Tables[0].Rows[0]["CreateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateDate"] != null && ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateUser"] != null && ds.Tables[0].Rows[0]["UpdateUser"].ToString() != "")
                {
                    model.UpdateUser = int.Parse(ds.Tables[0].Rows[0]["UpdateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateDate"] != null && ds.Tables[0].Rows[0]["UpdateDate"].ToString() != "")
                {
                    model.UpdateDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Valid"] != null && ds.Tables[0].Rows[0]["Valid"].ToString() != "")
                {
                    model.Valid = int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
    }
}
